package com.yutel.phone.binh.data.xmlhandler;

import java.util.ArrayList;

import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;

import com.yutel.phone.binh.data.vo.Video;

public class SAXforRecommendHandler extends DefaultHandler {
	private ArrayList<Video> videos;
	private Video video;

	public ArrayList<Video> getVideos() {
		return videos;
	}

	@Override
	public void startDocument() throws SAXException {
		videos = new ArrayList<Video>();
	}

	@Override
	public void startElement(String uri, String localname, String qname,
			Attributes attributes) throws SAXException {
		if ("video".equals(localname)) {
			video = new Video();
			video.setVid(attributes.getValue("menuId"));
			video.setName(attributes.getValue("name"));
			video.setPoster(attributes.getValue("poster"));
			video.setTotalNumber(attributes.getValue("totalNumber"));
			video.setScore(attributes.getValue("score"));
			video.setQualityLevel(attributes.getValue("qualityLevel"));
		}
	}

	@Override
	public void endElement(String uri, String localName, String qname)
			throws SAXException {
		if ("video".equals(localName) && video != null) {
			videos.add(video);
			video = null;
		}
	}
}
